package com.zzy.frame;
import javax.swing.JFrame;
import javax.swing.plaf.DimensionUIResource;
import com.zzy.factory.CommandFactory;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class view extends JFrame{
	//构建
    Font centerFont = new Font("楷体", Font.PLAIN, 30);
    SpringLayout SpringLayout = new SpringLayout();
    JPanel centerPanel = new JPanel(SpringLayout);
    theActionListener listener = new theActionListener();
    JButton Btn1 = new JButton("判别卡号类型");
    JButton Btn2 = new JButton("读入");
    JButton Btn3 = new JButton("查询");
    //背景
    JLayeredPane layeredPane = new JLayeredPane();
    ImageIcon icon = new ImageIcon("D:/eclipse2023/Bank/src/com/zzy/frame/fengjing.png");
    JPanel jPanel = new JPanel();
    JLabel jLabel = new JLabel(icon);
    //单例
    CommandFactory commandFactory = CommandFactory.getCommandFactory();
    public view() {
        super("用户管理界面");
        this.setSize(new DimensionUIResource(990, 600));
        centerPanel.add(Btn1);
        Btn1.setFont(centerFont);
        Btn1.addActionListener(listener);
        centerPanel.add(Btn2);
        Btn2.setFont(centerFont);
        Btn2.addActionListener(listener);
        centerPanel.add(Btn3);
        Btn3.setFont(centerFont);
        Btn3.addActionListener(listener);
        Container contentPane = getContentPane();
        contentPane.add(centerPanel);
        SpringLayout.putConstraint(javax.swing.SpringLayout.NORTH, Btn1, 100, javax.swing.SpringLayout.NORTH,
                contentPane);
        SpringLayout.putConstraint(javax.swing.SpringLayout.WEST, Btn1, 60, javax.swing.SpringLayout.WEST,
                contentPane);
        SpringLayout.putConstraint(javax.swing.SpringLayout.NORTH, Btn2, 0, javax.swing.SpringLayout.NORTH,
                Btn1);
        SpringLayout.putConstraint(javax.swing.SpringLayout.WEST, Btn2, 120, javax.swing.SpringLayout.EAST,
                Btn1);
        SpringLayout.putConstraint(javax.swing.SpringLayout.NORTH, Btn3, 100, javax.swing.SpringLayout.SOUTH,
                Btn1);
        SpringLayout.putConstraint(javax.swing.SpringLayout.WEST, Btn3, 0, javax.swing.SpringLayout.WEST,
                Btn1);
        //退出
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        //大小固定
        setResizable(false);
        //居中
        setLocationRelativeTo(null);
        //可视
        setVisible(true);
        // 设置背景
        jLabel.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());
        this.getLayeredPane().add(jLabel, Integer.MIN_VALUE);
        centerPanel.setOpaque(false);
        JPanel max = (JPanel) this.getContentPane();
        max.setOpaque(false);
        jPanel.add(jLabel);
        jPanel.setBounds(-10, -15, icon.getIconWidth(), icon.getIconHeight());
        layeredPane.add(jPanel, JLayeredPane.DEFAULT_LAYER);
        layeredPane.add(contentPane, JLayeredPane.MODAL_LAYER);
        this.setLayeredPane(layeredPane);
    }
    class theActionListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			if (e.getActionCommand() == "判别卡号类型") {
                commandFactory.setFlag(1);
                String input = JOptionPane.showInputDialog(rootPane, "输入卡号");
                if (input.length() == 0) {
                    JOptionPane.showMessageDialog(rootPane, "输入为空");
                } else {
                    commandFactory.build(input);
                }
            } else if (e.getActionCommand() == "读入") {
                commandFactory.setFlag(2);
                commandFactory.build("D:/eclipse2023/Bank/src/com/zzy/data/data.txt");
            } else if (e.getActionCommand() == "查询") {
                String input = JOptionPane.showInputDialog(rootPane, "输入你的卡号或姓名");
                commandFactory.setFlag(3);
                commandFactory.build(input);
            }
		}
    	
    }

}
